package com.leyou.item.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.leyou.common.dto.SpecParamDTO;
import com.leyou.common.dto.SpuDetailDTO;
import com.leyou.common.exception.LyException;
import com.leyou.item.entity.SpecParam;
import com.leyou.item.mapper.SpecParamMapper;
import com.leyou.item.service.SpecParamService;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class SpecParamServiceImpl extends ServiceImpl<SpecParamMapper, SpecParam> implements SpecParamService {

    @Override
    public List<SpecParamDTO> queryParamList(Long categoryId, Long groupId, Boolean searching) {
        //1.代码健壮性
        if (categoryId == null && groupId == null) {
            System.out.println("分类id和组id必须有一个不为空!!");
            throw new LyException(400, "分类id和组id必须有一个不为空!!");

        }
        //SELECT * FROM tb_spec_param
        // WHERE category_Id = 76 AND group_id =1 AND searching = 0
        //2. 查询
        List<SpecParam> list = query()
                .eq(categoryId != null, "category_id", categoryId)
                .eq(groupId != null, "group_id", groupId)
                .eq(searching != null, "searching", searching).list();


        return  SpecParamDTO.convertEntityList(list);
    }


}
